package com.ccc.demo2;

import scala.runtime.AbstractFunction3;

import java.io.Serializable;

//状态更新方法
public class MyVprog extends AbstractFunction3<Object, String, MyMessage, String> implements Serializable {

    @Override
    public String apply(Object id, String color, MyMessage msg) {
        System.out.println(String.format("id:%s, color:%s, msg:%s", id.toString(), color, msg,toString()));
        if(msg.getBlack() == 0  && msg.getWhite() == 0){
            return color;
        }

        if (color.equals("black")) {
            return "black";
        }

        float value = msg.getBlack() / (msg.getBlack() + msg.getWhite() + 0.0f);
        if (value >= 0.4f) {
            return "gray";
        }
        return "white";
    }
}
